﻿Public Class ctrTaiKhoan

    Private Sub btnThoat_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnThoat.Click
        frmMain.TabControl1.TabPages.Remove(frmMain.TabControl1.SelectedTab)
    End Sub

    Private Sub ctrTaiKhoan_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        gvTaiKhoan_Load()
        cmbLoaiTK.Items.Insert(0, "Quản lý")
        cmbLoaiTK.Items.Insert(1, "Nhân viên")
        cmbLoaiTK.SelectedIndex() = 0
    End Sub

    Private Sub gvTaiKhoan_Load()
        Dim bus As New TaiKhoanBUS()
        gvTaiKhoan.DataSource = bus.GetTable()
    End Sub

    Private Sub btnThem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnThem.Click
        Dim tmp As New TaiKhoanDTO()
        tmp.TenDangNhap = txtTenTK.Text
        tmp.MatKhau = txtMatKhau.Text
        tmp.LoaiTK = cmbLoaiTK.Text

        Dim bus As New TaiKhoanBUS()
        bus.Insert(tmp)

        gvTaiKhoan_Load()
    End Sub

    Private Sub btnLamMoi_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnLamMoi.Click
        txtTenTK.Text = ""
        txtMatKhau.Text = ""
        txtTenTK.Select()
    End Sub

    Private Sub btnXoa_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnXoa.Click
        Dim tmp As New TaiKhoanDTO()
        tmp.TenDangNhap = gvTaiKhoan.CurrentRow.Cells(0).Value.ToString()

        Dim bus As New TaiKhoanBUS()
        bus.Delete(tmp)

        gvTaiKhoan_Load()
    End Sub
End Class
